package net.shop.biz.db.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springmodules.cache.annotations.Cacheable;

import net.shop.biz.db.ProductVirtualCategoryService;
import net.shop.biz.service.FriendlyUrlService;
import net.shop.biz.vo.ProductVirtualCategoryVo;
import net.shop.dal.dao.ProductVirtualCategoryDao;
import net.shop.dal.entity.ProductVirtualCategory;

@Service
public class ProductVirtualCategoryServiceImpl extends BaseServiceImpl<ProductVirtualCategory, Integer> implements ProductVirtualCategoryService {

	@Resource
	private ProductVirtualCategoryDao productVirtualCategoryDao;
	@Resource
	private FriendlyUrlService friendlyUrlService;
	
	@Resource
	public void setBaseDao(ProductVirtualCategoryDao productVirtualCategoryDao) {
		super.setBaseDao(productVirtualCategoryDao);
	}

	public ProductVirtualCategory findByHaseCode(short languageId, long haseCode) {
		return productVirtualCategoryDao.findByHaseCode(languageId, haseCode);
	}

	@Cacheable(modelId="caching")
	public List<ProductVirtualCategory> getChildrenProductCategoryList(ProductVirtualCategory category) {
		List<ProductVirtualCategory> childs = productVirtualCategoryDao.getChildrenProductCategoryList(category);
		for (ProductVirtualCategory child : childs) {
			child.setVo(getValueObject(category, child));
		}
		return childs;
	}
	
	private ProductVirtualCategoryVo getValueObject(ProductVirtualCategory parent, ProductVirtualCategory currently) {
		ProductVirtualCategoryVo vo = new ProductVirtualCategoryVo();
		vo.setLinkUrl(friendlyUrlService.getProductVirtualCategoryUrl(parent, currently));
		vo.setPicUrl("http://images.bestbuy.com"+ currently.getCategoryPic());
		return vo;
	}

	public List<ProductVirtualCategory> getRootProductCategoryList(short languageId) {
		
		return null;
	}
}
